/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager.search;

import br.com.deployment.daoImpl.CategoryDAOImpl;
import br.com.deployment.daoImpl.QuestionnaireDAOImpl;
import br.com.deployment.entities.Category;
import br.com.deployment.entities.Questionnaire;
import br.com.deployment.utils.Msg;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author ely
 */
@ManagedBean
@SessionScoped
public class ManagerEditQuestionnaire {

    @EJB
    CategoryDAOImpl categoryService;
    
    @EJB
    QuestionnaireDAOImpl questionnaireService;
    
    private Questionnaire questionnaire;
    private Category category;
    
    
    private List<Category> categorys;
    private List<Category> selectCategory;

    public ManagerEditQuestionnaire() {
       category = new Category();
    }
    
    public List<Category> lstCategorys(){
        return categorys = categoryService.findAll();
    }
    
    
    public void update(){
        questionnaire.setCategorys(selectCategory);
        questionnaireService.update(questionnaire);
        Msg.messagemInfo("Questionário Atualizado com Sucesso ");
    }
    
    public void addCategorys() {
        categorys.add(category);
        category = new Category();
        System.out.println(categorys);
    }

    public void redirectEditQuestionnaire(String string, Questionnaire q) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            this.questionnaire = q;
            selectCategory = categoryService.findCategoryQuestionnaire(this.questionnaire);
            context.getExternalContext().redirect(string);
        } catch (IOException ex) {
            Logger.getLogger(ManagerEditQuestionnaire.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Questionnaire getQuestionnaire() {
        return questionnaire;
    }

    public void setQuestionnaire(Questionnaire questionnaire) {
        this.questionnaire = questionnaire;
    }

    public List<Category> getCategorys() {
        return categorys;
    }

    public void setCategorys(List<Category> categorys) {
        this.categorys = categorys;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public List<Category> getSelectCategory() {
        return selectCategory;
    }

    public void setSelectCategory(List<Category> selectCategory) {
        this.selectCategory = selectCategory;
    }
    
    
    
}
